home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / AmiVoGL_MDEV.lha / examples / fpatches.F < prev    next >
Text File  |  1991-06-07  |  6KB  |  310 lines

  1. c
  2. c    Draws patches of various bases
  3. c
  4.     program fpatch
  5.  
  6. #ifdef SGI
  7. #include "fgl.h"
  8. #include "fdevice.h"
  9. #else
  10. #include "fvogl.h"
  11. #include "fvodevice.h"
  12. #endif
  13.  
  14. c
  15. c  patch basis types
  16. c
  17.     integer *2 val, vminx, vmaxx, vminy, vmaxy
  18.     real bezier(4,4), cardinal(4, 4), bspline(4, 4)
  19.     real power(4, 4)
  20.     real x1(4, 4), y1(4, 4), z1(4, 4)
  21.     real x2(4, 4), y2(4, 4), z2(4, 4)
  22.  
  23.     character *50 labels(4)
  24.  
  25.     real    basis(64)
  26.     equivalence (basis(1), bezier(1, 1))
  27.     equivalence (basis(17), cardinal(1, 1))
  28.     equivalence (basis(33), bspline(1, 1))
  29.     equivalence (basis(49), power(1, 1))
  30.  
  31.     data bezier/
  32.      +        -1.0,    3.0,    -3.0,    1.0,
  33.      +        3.0,    -6.0,    3.0,    0.0,
  34.      +        -3.0,    3.0,    0.0,    0.0,
  35.      +        1.0,    0.0,    0.0,    0.0/ 
  36.  
  37.     data cardinal/
  38.      +        -0.5,    1.5,    -1.5,    0.5,
  39.      +        1.0,    -2.5,    2.0,    -0.5,
  40.      +        -0.5,    0.0,    0.5,    0.0,
  41.      +        0.0,    1.0,    0.0,    0.0/
  42.  
  43.     data bspline/
  44.      +         -0.166666,     0.5,     -0.5,     0.166666,
  45.      +         0.5,          -1.0,      0.5,     0.0,
  46.      +            -0.5,          0.0,      0.5,     0.0, 
  47.      +         0.166666,     0.666666, 0.166666, 0.0 /
  48.  
  49.     data power/
  50.      +        1.0, 0.0, 0.0, 0.0,
  51.      +        0.0, 1.0, 0.0, 0.0,
  52.      +        0.0, 0.0, 1.0, 0.0,
  53.      +        0.0, 0.0, 0.0, 1.0/
  54.  
  55.     data    x1 / 
  56.      +        0.0,   0.2588,   0.5,   0.7071,
  57.      +        0.0,   0.51764,  1.0,   1.4142,
  58.      +        0.0,   0.51764,  1.0,   1.4142,
  59.      +        0.0,   0.2588,   0.5,   0.7071/
  60.  
  61.     data    y1 / 
  62.      +        1.0,   0.966,   0.866,  0.7071,
  63.      +        2.0,   1.9318,  1.732,  1.4142,
  64.      +        2.0,   1.9318,  1.732,  1.4142,
  65.      +        1.0,   0.966,   0.866,  0.7071/
  66.  
  67.     data    z1 / 
  68.      +        1.0,   1.0,     1.0,    1.0,
  69.      +        1.0,   1.0,     1.0,    1.0,
  70.      +        0.0,   0.0,     0.0,    0.0,
  71.      +        0.0,   0.0,     0.0,    0.0/
  72.  
  73.     data    x2 / 
  74.      +        0.7071, 0.8660, 0.9660, 1.0,
  75.      +        1.4142, 1.7320, 1.932,  2.0,
  76.      +        1.4142, 1.7320, 1.932,  2.0,
  77.      +        0.7071, 0.8660, 0.9660, 1.0/
  78.  
  79.     data    y2 / 
  80.      +        0.7071, 0.5,    0.2588, 0.0,
  81.      +        1.4142, 1.0,    0.5176, 0.0,
  82.      +        1.4142, 1.0,    0.5176, 0.0,
  83.      +        0.7071, 0.5,    0.2588, 0.0/
  84.  
  85.     data    z2 / 
  86.      +        1.0,   1.0,     1.0,    1.0,
  87.      +        1.0,   1.0,     1.0,    1.0,
  88.      +        0.0,   0.0,     0.0,    0.0,
  89.      +        0.0,   0.0,     0.0,    0.0/
  90.  
  91.  
  92.     data labels /
  93.      +        'Bezier Patch(es)',
  94.      +        'Cardinal Patch(es)',
  95.      +        'B-Spline Patch(es)',
  96.      +        '''Power'' Patch(es)' /
  97.  
  98. c
  99. c  demonstrate patches
  100. c
  101.  
  102.     call winope('fpatches', 8)
  103.  
  104. c
  105. c We use the space bar to go to the next one...
  106. c
  107.     call unqdev(INPUTC)
  108.     call qdevic(SPACEK)
  109.  
  110. c
  111. c clear screen
  112. c
  113.     call color(BLACK)
  114.     call clear
  115. c
  116. c load a hershey font
  117. c
  118.     call hfont('times.r', 7)
  119.     call htexts(0.4, 0.4)
  120.  
  121. c
  122. c Set up two viewports (They actually overlap)
  123. c
  124.  
  125.     call getvie(vminx, vmaxx, vminy, vmaxy)
  126.  
  127.     minx = vminx
  128.     maxx = vmaxx
  129.     miny = vminy
  130.     maxy = vmaxy
  131.  
  132.     call viewpo(minx, (maxx - minx) / 10 * 6,
  133.      +              miny, (maxy - miny) / 10 * 6)
  134.  
  135.     call ortho(-2.0, 5.0, -2.0, 5.0, -2.0, 5.0)
  136.     call lookat(0.0, 0.0, 0.0, -3.0, 2.0, -4.0, 0.0)
  137. c
  138. c    Save it 
  139. c
  140.     call pushvi
  141.     call pushma
  142.  
  143.     call viewpo((maxx - minx) / 10 * 2, maxx,
  144.      +              (maxy - miny) / 10 * 2, maxy)
  145.  
  146.     call ortho(-2.0, 5.0, -2.0, 5.0, -2.0, 5.0)
  147.     call lookat(0.0, 0.0, 0.0, 3.0, 2.0, -4.0, 0.0)
  148.  
  149.  
  150. c
  151. c    patchcurves provides a number of curves in the t and u
  152. c    directions. patchprecision gives the minimum number of line
  153. c    segments making up the curves in the t and u directions. The
  154. c    actual number of linesegments in t or u is equal to the closest
  155. c    integer multiple of the number of curves, > nsegs, in t or u,
  156. c    greater than or equal to the number set by patchprecision in u or
  157. c    t. eg. curves in t will be made up of 21 line segments so that we
  158. c    can match up the 7 curves in u; curves in u will have 24 as 4 by 5
  159. c    gives 20.
  160. c
  161.     call patchc(4, 7)
  162.     call patchp(20, 20)
  163.  
  164.     do 10 i = 0, 3
  165.  
  166.         call axes
  167.  
  168.  
  169. c
  170. c         patchbasis sets the basis matrices for the t and u
  171. c         functions
  172. c
  173.         call defbas(i, basis(i*16 + 1))
  174.         call patchb(i, i)
  175.  
  176. c        Draw with viewport 2
  177. c
  178.         call move(0.0, 4.0, 0.0)
  179.         call hchars(labels(i + 1), nchars(labels(i + 1)))
  180.  
  181. c
  182. c        Now draw the patches according to the geometry matrices in
  183. c        x1, y1, and z1, x2, y2, z2.
  184. c
  185.         call drawhu(x1, y1, z1)
  186.         call patch(x1, y1, z1)
  187.  
  188.         call drawhu(x2, y2, z2)
  189.         call patch(x2, y2, z2)
  190. c
  191. c         Now with viewport 1
  192. c
  193.         call popvie
  194.         call popmat
  195.  
  196.         call axes
  197.  
  198.         call move(0.0, 4.0, 0.0)
  199.         call hchars(labels(i + 1), nchars(labels(i + 1)))
  200.  
  201. c
  202. c        now draw the patches according to the geometry matrices in
  203. c         x1, y1, and z1, x2, y2, z2.
  204. c
  205.         call drawhu(x1, y1, z1)
  206.         call patch(x1, y1, z1)
  207.  
  208.         call drawhu(x2, y2, z2)
  209.         call patch(x2, y2, z2)
  210.  
  211.         idum = qread(val)
  212. c
  213. c        Eat the up event as well....
  214. c
  215.         idum = qread(val)
  216.  
  217. c
  218. c        Clear viewport 1.
  219. c
  220.         call color(BLACK)
  221.         call clear
  222. c
  223. c         Save viewport 1 again and reset to viewport 2
  224. c
  225.         call pushvi
  226.         call pushma
  227.  
  228.         call viewpo((maxx - minx) / 10 * 2, maxx,
  229.      +                      (maxy - miny) / 10 * 2, maxy)
  230.  
  231.         call ortho(-1.5, 5.0, -1.5, 5.0, -1.5, 5.0)
  232.         call lookat(0.0, 0.0, 0.0, 3.0, 2.0, -4.0, 0.0)
  233.  
  234.         call color(BLACK)
  235.         call clear
  236. 10    continue
  237.  
  238.     call gexit
  239.  
  240.     end
  241.  
  242.  
  243.     subroutine drawhu(x, y, z)
  244.     real    x(4,4), y(4,4), z(4,4)
  245.  
  246. #include "fvogl.h"
  247.  
  248.     call color(MAGENT)    
  249.     do 10 i = 1,4
  250.         call move(x(i,1), y(i,1), z(i,1))
  251.         do 5 j = 1,4
  252.             call draw(x(i,j), y(i,j), z(i,j))
  253. 5        continue
  254. 10    continue
  255.     
  256.     do 20 i = 1,4
  257.         call move(x(1,i), y(1,i), z(1,i))
  258.         do 15 j = 1,4
  259.             call draw(x(j,i), y(j,i), z(j,i))
  260. 15        continue
  261. 20    continue
  262.  
  263.     call color(GREEN)
  264.     end
  265.  
  266. c
  267. c axes
  268. c
  269. c    draw the axes
  270. c
  271.  
  272.     subroutine axes
  273.  
  274.     integer YELLOW
  275.     parameter (YELLOW = 3)
  276.  
  277.     call color(YELLOW)
  278.     call move(0.0, 0.0, 0.0)
  279.     call draw(4.0, 0.0, 0.0)
  280.  
  281.     call move(0.0, 0.0, 0.0)
  282.     call draw(0.0, 4.0, 0.0)
  283.  
  284.     call move(0.0, 0.0, 0.0)
  285.     call draw(0.0, 0.0, 4.0)
  286.  
  287.     end
  288. c
  289. c nchars
  290. c
  291. c return the real length of a string padded with blanks
  292. c
  293.     integer function nchars(str)
  294.     character *(*) str
  295.  
  296.     do 10 i = len(str), 1, -1
  297.         if (str(i:i) .ne. ' ') then
  298.             nchars = i
  299.             return
  300.         end if
  301. 10      continue
  302.  
  303.     nchars = 0
  304.  
  305.     return
  306.  
  307.     end
  308.